<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 16:30
 */

include_once '../../mysql/DbTools.php';
$username =  $_POST['username'];
$pwd =  $_POST['pwd'];

$Url = '';
$msg = '';

$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bank');

echo '数据库连接成功!<br/>';

DbTools::setConn($conn);
$data = DbTools::select('select CardNo,CardPwd from bankcard');

for ($i=0;$i<count($data);$i++){
    if ($username == $data[0]['CardNo'] && $pwd == $data[0]['CardPwd'])
    {
        $userKey = md5($username.$pwd);
        setcookie('userID',$userKey,time()+24*3600);
        session_start();
        $_SESSION[$userKey]=[
            'username'=>$username,
            'pwd'=>$pwd
        ];

        $msg = '登录成功';
        $Url = 'userInfo.php';
    }else{
        $msg = '用户不存在或用户名密码错误';
        $Url = '/Shop/login.php';
    }
}

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<input type="hidden" id="msg" value="<?php echo $msg ?>">
<input type="hidden" id="Url" value="<?php echo $Url ?>">
</body>
<script>
    onload = function () {
        var newUrl = document.getElementById('Url').value;
        var msg = document.getElementById('msg').value;
        alert(msg);
        location.href = newUrl;
    }
</script>
</html>
